package com.baizhi.service.impl;

import com.baizhi.annotation.LogAnnotation;
import com.baizhi.dao.GuruDao;
import com.baizhi.entity.Guru;
import com.baizhi.service.GuruService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GuruServiceImpl implements GuruService {
    @Autowired
    private GuruDao guruDao;
    @Override
    public Map insertGuru(Guru guru) {
        Map map=new HashMap();
        int count=guruDao.insertGuru(guru);
        if(count>0){
            map.put("isInsert",true);
        }else{
            map.put("isInsert",false);
        }
        return map;
    }
    @Override
    public Map deleteGuruById(int guruId) {
        Map map=new HashMap();
        int count=guruDao.deleteGuruById(guruId);
        if(count>0){
            map.put("isDelete",true);
        }else{
            map.put("isDelete",false);
        }
        return map;
    }
    @Override
    public Map updateGuru(Guru guru) {
        Map map=new HashMap();
        int count=guruDao.updateGuru(guru);
        if(count>0){
            map.put("isUpdate",true);
        }else{
            map.put("isUpdate",false);
        }
        return map;
    }
    @Override

    public Map showAll(int page, int limit) {
        Map map=new HashMap();
        int offset=(page-1)*limit;
        int count=guruDao.selectCount();
        List<Guru> list=guruDao.selectAllGuru(offset,limit);

        map.put("data",list);
        map.put("count",count);
        map.put("code",0);
        map.put("msg","");
        return map;
    }

    @Override
    public Guru selectOne(int guruId) {
        Guru guru=guruDao.selectOne(guruId);
        return guru;
    }

    @Override
    @LogAnnotation(value = "ddd",type = "ddd")
    public List<Guru> selectAll() {
        List<Guru> download=guruDao.selectAll();
        return download;
    }
}
